package com.vains.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * 用户接口
 *
 * @author vains
 * @date 2021/4/3 0:21
 */
@RestController
@Api(tags = "用户接口")
@RequestMapping("/user")
public class UserController {

    @GetMapping("/test")
    @ApiOperation("测试接口")
    @PreAuthorize("hasAuthority('/test/test01')")
    public String test() {
        return "hello world!";
    }

    @GetMapping("/user")
    @ApiOperation("根据token获取当前登录用户，只需传入参数，principal参数由框架自动填充")
    public Principal user(Principal principal) {
        return principal;
    }

}
